package edu.pku.sei.autounit.tester;

import java.util.ArrayList;
import java.util.List;

import edu.pku.sei.autounit.core.DefaultMethodInvocation;
import edu.pku.sei.autounit.core.MethodInvocation;
import edu.pku.sei.autounit.core.Variable;
import edu.pku.sei.autounit.core.VariableFactory;
import edu.pku.sei.autounit.reflect.Method;
import edu.pku.sei.autounit.reflect.Type;
import edu.pku.sei.autounit.util.NameFactory;

public class SimpleMethodGenerator implements MethodGenerator{

	
	public List<MethodInvocation> generate(Method method, VariableFactory vf,
			NameFactory nf) {
		
		Variable runObject = null ;
		if(!method.isAbstract())
			runObject = vf.getNonNullVariable(method.getDeclaringClass(), 
				nf.getName(method.getDeclaringClass().getFullName(),NameFactory.RUNOBJECT), nf);
		
		Type [] pts = method.getParameters();
		Variable [] ps = new Variable [pts.length];
		for(int i = 0;i< ps.length;i++)
			ps[i] = vf.getNonNullVariable(pts[i], 
					nf.getName(pts[i].getFullName(),NameFactory.PARAMETER), nf);
		
		List<MethodInvocation> r = new ArrayList<MethodInvocation>();
		r.add(new DefaultMethodInvocation(method, runObject, ps));
		return r;
	}
}
